﻿using System.Collections.Generic;
using Newtonsoft.Json;
using RestSharp;

namespace mtg_trader.Core.BlackLotusProject
{
    public class RestfulBlackLotusProject
    {
        private const string BaseAddress = "http://blacklotusproject.com/json";
        private readonly Dictionary<BlackLotusProjectMethods, string> _blackLotusProjectMethods;

        public RestfulBlackLotusProject()
        {
            _blackLotusProjectMethods = new Dictionary<BlackLotusProjectMethods, string>
                {
                    {BlackLotusProjectMethods.Cards, ""}
                };
        }

        public RestClient SetupRestClient()
        {
            var restClient = new RestClient(BaseAddress);
            return restClient;
        }

        public BlackLotusProjectPriceResult GetBlackLotusProjectCardPrices(string cardName)
        {
            var restClient = SetupRestClient();
            var restRequest = new RestRequest(_blackLotusProjectMethods[BlackLotusProjectMethods.Cards], Method.GET);
            restRequest.AddParameter("cards", cardName.Replace(' ', '+'));

            var result = restClient.Execute(restRequest);
            var parsedResult = JsonConvert.DeserializeObject<BlackLotusProjectPriceResult>(result.Content);

            return parsedResult;

        }


    }

    public class BlackLotusProjectPriceResult
    {
        public IEnumerable<BlackLotusProjectCardResult> cards { get; set; }
        public string currency { get; set; }
    }

    public class BlackLotusProjectCardResult
    {
        public decimal high { get; set; }
        public int volume { get; set; }
        public decimal percent_change { get; set; }
        public string name { get; set; }
        public string url { get; set; }
        public decimal price { get; set; }
        public string set_code { get; set; }
        public decimal average { get; set; }
        public decimal change { get; set; }
        public decimal low { get; set; }
    }

    public enum BlackLotusProjectMethods
    {
        Cards,

    }
}
